home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / src / GLperf3.12-src.lha / GLperf / Parse.y < prev    next >
Encoding:
Text File  |  1997-05-20  |  17.1 KB  |  552 lines

  1. /*
  2.  *   (C) COPYRIGHT International Business Machines Corp. 1993
  3.  *   All Rights Reserved
  4.  *   Licensed Materials - Property of IBM
  5.  *   US Government Users Restricted Rights - Use, duplication or
  6.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7.  */
  8.  
  9. /*
  10.  * Permission to use, copy, modify, and distribute this software and its
  11.  * documentation for any purpose and without fee is hereby granted, provided
  12.  * that the above copyright notice appear in all copies and that both that
  13.  * copyright notice and this permission notice appear in supporting
  14.  * documentation, and that the name of I.B.M. not be used in advertising
  15.  * or publicity pertaining to distribution of the software without specific,
  16.  * written prior permission. I.B.M. makes no representations about the
  17.  * suitability of this software for any purpose.  It is provided "as is"
  18.  * without express or implied warranty.
  19.  *
  20.  * I.B.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL I.B.M.
  22.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  23.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  24.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  25.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  26.  *
  27.  * Author:  John Spitzer, IBM AWS Graphics Systems (Austin)
  28.  */
  29. %start PrintIt
  30. %{
  31. #ifndef WIN32
  32. extern int yylineno;
  33. #else
  34. static int yylineno;
  35. #endif
  36. #if defined(WIN32)
  37. #include <windows.h>
  38. #elif defined( __OS2__)
  39. #include <os2.h>
  40. #ifdef YYBYACC
  41. int yylex( void);
  42. #endif
  43. #endif
  44. #include "stdio.h"
  45. #include "stdlib.h"
  46. #include "Global.h"
  47. #include "PropName.h"
  48. #include "TestName.h"
  49. #include "Test.h"
  50. #include "TestList.h"
  51. #include "Attr.h"
  52. #include "AttrList.h"
  53. #include "Prop.h"
  54. #include "PropList.h"
  55. #include "NameList.h"
  56. #include "Suite.h"
  57. #include <malloc.h>
  58. #include <math.h>
  59.  
  60. extern int printMode;
  61. %}
  62. %union {
  63.   AttributePtr attr;
  64.   AttributeListPtr attrList;
  65.   PropertyPtr prop;
  66.   PropertyListPtr propList;
  67.   PropNameListPtr propNameList;
  68.   TestPtr test;
  69.   TestListPtr testList;
  70.   SuitePtr suite;
  71.   int ival;
  72.   float fval;
  73.   double dval;
  74.   short sval;
  75.   unsigned uval;
  76. }
  77.  
  78. %token <ival> testName
  79. %token <attr> attrName wildcard PropName errorName
  80. %token <ival> openCurly closeCurly openBracket closeBracket openParen closeParen From To step Percent Printf comma
  81.  
  82. %type <attrList> AttrsDesc AttrListDesc RangeDesc PrintfDesc
  83. %type <prop> PropDesc
  84. %type <propList> PropListDesc
  85. %type <propNameList> PropNameList CommaPropNameList
  86. %type <suite> SuiteDesc PrintIt
  87.  
  88. %%
  89. PrintIt        : SuiteDesc
  90.         {
  91.             /* Suite__PrintOp($1); */ /* For Debugging */
  92.             Suite__Run($1, printMode);
  93.             delete_Suite($1);
  94.         }
  95.         ;
  96.  
  97. SuiteDesc    : SuiteDesc PropDesc
  98.         {
  99.             Suite__ParseGlobal($1, $2);
  100.             $$ = $1;
  101.         }
  102.         | SuiteDesc testName openCurly PropListDesc closeCurly
  103.         {
  104.             Suite__ParseTest($1, $2, $4);
  105.             $$ = $1;
  106.         }
  107.         | SuiteDesc testName
  108.         {
  109.             Suite__ParseTest($1, $2, NULL);
  110.             $$ = $1;
  111.         }
  112.         | SuiteDesc testName openCurly closeCurly
  113.         {
  114.             Suite__ParseTest($1, $2, NULL);
  115.             $$ = $1;
  116.         }
  117.         | testName openCurly closeCurly
  118.         {
  119.             SuitePtr suite = new_Suite();
  120.             Suite__ParseTest(suite, $1, NULL);
  121.             $$ = suite;
  122.         }
  123.         | testName openCurly PropListDesc closeCurly
  124.         {
  125.             SuitePtr suite = new_Suite();
  126.             Suite__ParseTest(suite, $1, $3);
  127.             $$ = suite;
  128.         }
  129.         | testName
  130.         {
  131.             SuitePtr suite = new_Suite();
  132.             Suite__ParseTest(suite, $1, NULL);
  133.             $$ = suite;
  134.         }
  135.         | PropDesc
  136.         {
  137.             SuitePtr suite = new_Suite();
  138.             Suite__ParseGlobal(suite, $1);
  139.             $$ = suite;
  140.         }
  141.         | SuiteDesc errorName openCurly PropListDesc closeCurly
  142.         {
  143.             char* buffer;
  144.             Attribute__StringOf($2, &buffer);
  145.             printf("GLperf: Line %d, Bad test name \"%s\"\n",
  146.                Attribute__GetLineNum($2), buffer);
  147.             exit(1);
  148.         }
  149.         | SuiteDesc errorName
  150.         {
  151.             char* buffer;
  152.             Attribute__StringOf($2, &buffer);
  153.             printf("GLperf: Line %d, Bad test name \"%s\"\n",
  154.                Attribute__GetLineNum($2), buffer);
  155.             exit(1);
  156.         }
  157.         | SuiteDesc errorName openCurly closeCurly
  158.         {
  159.             char* buffer;
  160.             Attribute__StringOf($2, &buffer);
  161.             printf("GLperf: Line %d, Bad test name \"%s\"\n",
  162.                Attribute__GetLineNum($2), buffer);
  163.             exit(1);
  164.         }
  165.         | errorName openCurly closeCurly
  166.         {
  167.             char* buffer;
  168.             Attribute__StringOf($1, &buffer);
  169.             printf("GLperf: Line %d, Bad test name \"%s\"\n",
  170.                Attribute__GetLineNum($1), buffer);
  171.             exit(1);
  172.         }
  173.         | errorName openCurly PropListDesc closeCurly
  174.         {
  175.             char* buffer;
  176.             Attribute__StringOf($1, &buffer);
  177.             printf("GLperf: Line %d, Bad test name \"%s\"\n",
  178.                Attribute__GetLineNum($1), buffer);
  179.             exit(1);
  180.         }
  181.         | errorName
  182.         {
  183.             char* buffer;
  184.             Attribute__StringOf($1, &buffer);
  185.             printf("GLperf: Line %d, Bad test name \"%s\"\n",
  186.                Attribute__GetLineNum($1), buffer);
  187.             exit(1);
  188.         }
  189.         | SuiteDesc testName openCurly error
  190.         {
  191.             printf("GLperf: Near line %d, missing \"}\"\n", yylineno);
  192.             exit(1);
  193.         }
  194.         | SuiteDesc testName openCurly PropListDesc error
  195.         {
  196.             printf("GLperf: Near line %d, missing \"}\"\n", yylineno);
  197.             exit(1);
  198.         }
  199.         | testName openCurly error
  200.         {
  201.             printf("GLperf: Near line %d, missing \"}\"\n", yylineno);
  202.             exit(1);
  203.         }
  204.         | testName openCurly PropListDesc error
  205.         {
  206.             printf("GLperf: Near line %d, missing \"}\"\n", yylineno);
  207.             exit(1);
  208.         }
  209.         ;
  210.  
  211. PropListDesc    : PropListDesc PropDesc
  212.         {
  213.             PropertyList__AddProperty($1, $2);
  214.             $$ = $1;
  215.         }
  216.         | PropDesc
  217.         {
  218.             PropertyListPtr propList = new_PropertyList();
  219.             PropertyList__AddProperty(propList, $1);
  220.             $$ = propList;
  221.         }
  222.         ;
  223.  
  224. PropDesc    : openParen PropName AttrsDesc closeParen
  225.         {
  226.             PropertyPtr prop;
  227.             PropNameListPtr propNameList = new_PropNameList();
  228.             int propName, propNameLineNum;
  229.             Attribute__IntOf($2, &propName);
  230.             propNameLineNum = Attribute__GetLineNum($2);
  231.             PropNameList__AddPropName(propNameList, propName, propNameLineNum);
  232.             prop = new_Property(propNameList, $3);
  233.             delete_Attribute($2);
  234.             $$ = prop;
  235.         }
  236.         | openParen errorName AttrsDesc closeParen
  237.         {
  238.             char* buffer;
  239.             Attribute__StringOf($2, &buffer);
  240.             printf("GLperf: Line %d, Bad property name \"%s\"\n",
  241.                Attribute__GetLineNum($2), buffer);
  242.             exit(1);
  243.         }
  244.         | openParen testName AttrsDesc closeParen
  245.         {
  246.             printf("GLperf: Near line %d, Test name erroneously used where a property should be\n",
  247.                yylineno);
  248.             exit(1);
  249.         }
  250.         | openParen attrName AttrsDesc closeParen
  251.         {
  252.             printf("GLperf: Line %d, Attribute erroneously used where a property should be\n",
  253.                Attribute__GetLineNum($2));
  254.             exit(1);
  255.         }
  256.         | openParen openBracket PropNameList closeBracket AttrsDesc closeParen
  257.         {
  258.             PropertyPtr prop = new_Property($3, $5);
  259.             $$ = prop;
  260.         }
  261.         | openParen openBracket errorName closeBracket AttrsDesc closeParen
  262.         {
  263.             char* buffer;
  264.             Attribute__StringOf($3, &buffer);
  265.             printf("GLperf: Line %d, Bad property name \"%s\" in property list\n",
  266.                Attribute__GetLineNum($3), buffer);
  267.             exit(1);
  268.         }
  269.         | openParen openBracket testName closeBracket AttrsDesc closeParen
  270.         {
  271.             printf("GLperf: Near line %d, Test name erroneously used in printf argument list, which must contain only property names\n",
  272.                yylineno);
  273.             exit(1);
  274.         }
  275.         | openParen openBracket attrName closeBracket AttrsDesc closeParen
  276.         {
  277.             printf("GLperf: Line %d, Attribute erroneously used in printf argument list, which must contain only property names\n",
  278.                Attribute__GetLineNum($3));
  279.             exit(1);
  280.         }
  281.         ;
  282.  
  283. PropNameList    : PropNameList PropName
  284.         {
  285.             int propName, propNameLineNum;
  286.             Attribute__IntOf($2, &propName);
  287.             propNameLineNum = Attribute__GetLineNum($2);
  288.             PropNameList__AddPropName($1, propName, propNameLineNum);
  289.             delete_Attribute($2);
  290.             $$ = $1;
  291.         }
  292.         | PropNameList errorName
  293.         {
  294.             char* buffer;
  295.             Attribute__StringOf($2, &buffer);
  296.             printf("GLperf: Line %d, Bad property name \"%s\" in property list\n",
  297.                Attribute__GetLineNum($2), buffer);
  298.             exit(1);
  299.         }
  300.         | PropNameList attrName
  301.         {
  302.             printf("GLperf: Line %d, Attribute erroneously used in property list\n",
  303.                Attribute__GetLineNum($2));
  304.             exit(1);
  305.         }
  306.         | PropNameList testName
  307.         {
  308.             printf("GLperf: Near line %d, Test name erroneously used in property list\n",
  309.                yylineno);
  310.             exit(1);
  311.         }
  312.         | PropName
  313.         {
  314.             PropNameListPtr propNameList = new_PropNameList();
  315.             int propName, propNameLineNum;
  316.             Attribute__IntOf($1, &propName);
  317.             propNameLineNum = Attribute__GetLineNum($1);
  318.             PropNameList__AddPropName(propNameList, propName, propNameLineNum);
  319.             delete_Attribute($1);
  320.             $$ = propNameList;
  321.         }
  322.         ;
  323.  
  324. CommaPropNameList    : CommaPropNameList comma PropName
  325.         {
  326.             int propName, propNameLineNum;
  327.             Attribute__IntOf($3, &propName);
  328.             propNameLineNum = Attribute__GetLineNum($3);
  329.             PropNameList__AddPropName($1, propName, propNameLineNum);
  330.             delete_Attribute($3);
  331.             $$ = $1;
  332.         }
  333.         | CommaPropNameList comma errorName
  334.         {
  335.             char* buffer;
  336.             Attribute__StringOf($3, &buffer);
  337.             printf("GLperf: Line %d, Bad property name \"%s\" in printf argument list, which must contain only property names\n",
  338.                Attribute__GetLineNum($3), buffer);
  339.             exit(1);
  340.         }
  341.         | CommaPropNameList comma testName
  342.         {
  343.             printf("GLperf: Near line %d, Test name erroneously used in printf argument list, which must contain only property names\n",
  344.                yylineno);
  345.             exit(1);
  346.         }
  347.         | CommaPropNameList comma attrName
  348.         {
  349.             printf("GLperf: Line %d, Attribute erroneously used in printf argument list, which must contain only property names\n",
  350.                Attribute__GetLineNum($3));
  351.             exit(1);
  352.         }
  353.         | PropName
  354.         {
  355.             PropNameListPtr propNameList = new_PropNameList();
  356.                     int propName, propNameLineNum;
  357.                     Attribute__IntOf($1, &propName);
  358.                     propNameLineNum = Attribute__GetLineNum($1);
  359.             PropNameList__AddPropName(propNameList, propName, propNameLineNum);
  360.             delete_Attribute($1);
  361.             $$ = propNameList;
  362.         }
  363.         ;
  364.  
  365. AttrsDesc    : wildcard
  366.         {
  367.             AttributeListPtr attrList = new_AttributeList();
  368.             AttributeList__AddAttribute(attrList, $1);
  369.             $$ = attrList;
  370.         }
  371.         | AttrListDesc
  372.         {
  373.             $$ = $1;
  374.         }
  375.         | RangeDesc
  376.         {
  377.             $$ = $1;
  378.         }
  379.         | PrintfDesc
  380.         {
  381.             $$ = $1;
  382.         }
  383.         ;
  384.  
  385. PrintfDesc    : Printf openParen attrName comma CommaPropNameList closeParen
  386.         {
  387.             char* sval;
  388.             if (Attribute__StringOf($3, &sval)) {
  389.             PrintfStringPtr printfString = new_PrintfString(sval, $5);
  390.             AttributePtr attr = new_Attribute_PrintfString(printfString);
  391.                 AttributeListPtr attrList = new_AttributeList();
  392.                 AttributeList__AddAttribute(attrList, attr);
  393.                 $$ = attrList;
  394.             } else {
  395.             printf("GLperf: Line %d, Printf format must be a string\n", Attribute__GetLineNum($3));
  396.             exit(1);
  397.             }
  398.         }
  399.         | Printf openParen attrName comma errorName closeParen
  400.         {
  401.             char* buffer;
  402.             Attribute__StringOf($5, &buffer);
  403.             printf("GLperf: Line %d, Bad property name \"%s\" in printf argument list, which must contain only property names\n",
  404.                Attribute__GetLineNum($5), buffer);
  405.             exit(1);
  406.         }
  407.         ;
  408.  
  409. RangeDesc    : From attrName To attrName
  410.         {
  411.             int ival, fromival, toival;
  412.             float fval, fromfval, tofval;
  413.  
  414.             if (Attribute__IntOf($2, &fromival) && Attribute__IntOf($4, &toival)) {
  415.             if (fromival > toival) {
  416.                 printf("GLperf: Line %d, Range invalid\n", Attribute__GetLineNum($2));
  417.                    exit(1);
  418.             } else {
  419.                 AttributeListPtr attrList = new_AttributeList();
  420.                 for (ival=fromival; ival<=toival; ival++) {
  421.                 AttributeList__AddAttribute(attrList, new_Attribute_Int(ival));
  422.                 }
  423.                 $$ = attrList;
  424.             }
  425.             } else if (Attribute__FloatOf($2, &fromfval)) {
  426.             if (Attribute__FloatOf($4, &tofval)) {
  427.                 if (fromfval > tofval) {
  428.                 printf("GLperf: Line %d, Range invalid\n", Attribute__GetLineNum($2));
  429.                 exit(1);
  430.                 } else {
  431.                 AttributeListPtr attrList = new_AttributeList();
  432.                 for (fval=fromfval; fval<=tofval; fval++) {
  433.                     AttributeList__AddAttribute(attrList, new_Attribute_Float(fval));
  434.                 }
  435.                 $$ = attrList;
  436.                 }
  437.             } else {
  438.                 printf("GLperf: Line %d, Range from/to values of different types\n", Attribute__GetLineNum($2));
  439.                 exit(1);
  440.             }
  441.             } else {
  442.             printf("GLperf: Line %d, Range of an unsupported type\n", Attribute__GetLineNum($2));
  443.             exit(1);
  444.             }
  445.         }
  446.         | From attrName To attrName step attrName
  447.         {
  448.             int ival, fromival, toival, stepival;
  449.             float fval, fromfval, tofval, stepfval;
  450.  
  451.                     if (Attribute__IntOf($2, &fromival) && Attribute__IntOf($4, &toival) && Attribute__IntOf($6, &stepival)) {
  452.             if ((toival - fromival) * stepival < 0) {
  453.                 printf("GLperf: Line %d, Range invalid\n", Attribute__GetLineNum($2));
  454.                 exit(1);
  455.             } else {
  456.                 AttributeListPtr attrList = new_AttributeList();
  457.                 if (fromival < toival)
  458.                 for (ival=fromival; ival<=toival; ival+=stepival)
  459.                                     AttributeList__AddAttribute(attrList, new_Attribute_Int(ival));
  460.                 else
  461.                 for (ival=fromival; ival>=toival; ival+=stepival)
  462.                                     AttributeList__AddAttribute(attrList, new_Attribute_Int(ival));
  463.                 $$ = attrList;
  464.             }
  465.                     } else if (Attribute__FloatOf($2, &fromfval) &&
  466.                                Attribute__FloatOf($4, &tofval) &&
  467.                    Attribute__FloatOf($6, &stepfval)) {
  468.             if ((tofval - fromfval) * stepfval < 0.0) {
  469.                             printf("GLperf: Line %d, Range invalid\n", Attribute__GetLineNum($2));
  470.                 exit(1);
  471.             } else {
  472.                 AttributeListPtr attrList = new_AttributeList();
  473.                 if (fromfval < tofval)
  474.                 for (fval=fromfval; fval<=tofval; fval+=stepfval)
  475.                                     AttributeList__AddAttribute(attrList, new_Attribute_Float(fval));
  476.                 else
  477.                     for (fval=fromfval; fval>=tofval; fval+=stepfval)
  478.                                     AttributeList__AddAttribute(attrList, new_Attribute_Float(fval));
  479.                 $$ = attrList;
  480.             }
  481.             } else {
  482.                         printf("Line %d: Range of unsupported or dissimilar types\n", Attribute__GetLineNum($2));
  483.             exit(1);
  484.             } 
  485.         }
  486.         | From attrName To attrName step attrName Percent
  487.         {
  488.             int ival, fromival, toival, stepival;
  489.             float fval, fromfval, tofval, stepfval;
  490.  
  491.                     if (Attribute__IntOf($2, &fromival) &&
  492.                         Attribute__IntOf($4, &toival) &&
  493.                         Attribute__IntOf($6, &stepival)) {
  494.                         if ((toival - fromival) * stepival < 0 ||
  495.                             fromival <= 0) {
  496.                             printf("GLperf: Line %d, Range invalid\n", Attribute__GetLineNum($2));
  497.                             exit(1);
  498.                         } else {
  499.                             float percentage = (float)stepival / 100.;
  500.                             AttributeListPtr attrList = new_AttributeList();
  501.                             if (fromival < toival)
  502.                                 for (ival=fromival; ival<=toival; ival += max(floor((float)ival * percentage + .5), 1))
  503.                                     AttributeList__AddAttribute(attrList, new_Attribute_Int(ival));
  504.                             else
  505.                                 for (ival=fromival; ival>=toival; ival += min(floor((float)ival * percentage + .5), -1))
  506.                                     AttributeList__AddAttribute(attrList, new_Attribute_Int(ival));
  507.                             $$ = attrList;
  508.                         }
  509.                     } else if (Attribute__FloatOf($2, &fromfval) &&
  510.                                Attribute__FloatOf($4, &tofval) &&
  511.                                Attribute__FloatOf($6, &stepfval)) {
  512.                         if ((tofval - fromfval) * stepfval < 0.0 ||
  513.                             fromival <= 0.) {
  514.                             printf("GLperf: Line %d, Range invalid\n", Attribute__GetLineNum($2));
  515.                             exit(1);
  516.                         } else {
  517.                             float percentage = stepfval / 100. + 1.;
  518.                             AttributeListPtr attrList = new_AttributeList();
  519.                             if (fromfval < tofval)
  520.                                 for (fval=fromfval; fval<=tofval; fval = fval * percentage)
  521.                                     AttributeList__AddAttribute(attrList, new_Attribute_Float(fval));
  522.                             else
  523.                                 for (fval=fromfval; fval>=tofval; fval = fval * percentage)
  524.                                     AttributeList__AddAttribute(attrList, new_Attribute_Float(fval));
  525.                             $$ = attrList;
  526.                         }
  527.                     } else {
  528.                         printf("GLperf, Line %d: Range of unsupported or dissimilar types\n", Attribute__GetLineNum($2));
  529.                         exit(1);
  530.                     }
  531.                 }
  532.                 ;
  533.  
  534. AttrListDesc    : AttrListDesc attrName
  535.         {
  536.             AttributeList__AddAttribute($1, $2);
  537.             $$ = $1;
  538.         }
  539.         | attrName
  540.         {
  541.             AttributeListPtr attrList = new_AttributeList();
  542.             AttributeList__AddAttribute(attrList, $1);
  543.             $$ = attrList;
  544.         }
  545.         ;
  546.  
  547. %%
  548. yyerror(char* s)
  549. {
  550.      fprintf (stderr, "GLperf: Near line %d, %s\n", yylineno, s);
  551. }
  552.